package com.example.cnedujnux2022101878;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button buttonCalculate = this.findViewById(R.id.buttonCalculate);
        EditText editTextScores = this.findViewById(R.id.editTextInput);
        TextView textViewScore = this.findViewById(R.id.textViewResult);

        buttonCalculate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String scores = editTextScores.getText().toString();
                String[] arrayScore = scores.split(",");
                BowlingGame game = new  BowlingGame();
                for(int i = 0;i< arrayScore.length;i++){
                    game.roll(Integer.parseInt(arrayScore[i]));
                }
                textViewScore.setText("Total score is:" + game.score());
            }
        });
    }
}